#include "obstacle.h"
#include <algorithm>

Obstacle::Obstacle() :position()
{
	std::fill(Tab,Tab+10,nullptr);
}

Obstacle::~Obstacle()
{
	std::for_each(Tab,Tab+10,[](hitbox* H){ if (H) delete H; });
}

bool Obstacle::Collision(hitbox& hit) const
{
	return std::any_of(Tab,Tab+10,[&hit](const hitbox* H){ if (H) return hit.collision(*H); return false; });
}

bool Obstacle::Collision(Obstacle& ob) const 
{
	return std::any_of(Tab,Tab+10,[&ob](hitbox* H){ if (H) return ob.Collision(*H); return false; });
}

bool Obstacle::operator()(int taillex,int tailley,int taillez)
{
	int i=0;
	while (Tab[i]!=nullptr)
		i++;

	if (i>9)
		return false;
	Tab[i]=new hitboxRECT(&position,taillex,tailley,taillez);
	return true;
}

bool Obstacle::operator()(double rayon)
{
	int i=0;
	while (Tab[i]!=nullptr)
		i++;
	if (i>9)
		return false;
	Tab[i]=new hitboxCERCL(&position,rayon);
	return true;
}

